package com.java.tutorials.spring.ProSpring4.ch6.springJdbcAnnotations;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType;

import javax.sql.DataSource;

/**
 * Created by xuzhike on 2016/2/24.
 */
@Configuration
public class JdbcConfig {
    @Bean
    public DataSource dataSource() {
        return new EmbeddedDatabaseBuilder()
                .setType(EmbeddedDatabaseType.H2)
                //.addScripts("classpath:ProSpring4/ch5/springJdbcAnnotations/schema.sql","classpath:ProSpring4/ch5/springJdbcAnnotations/stored-function.sql", "classpath:ProSpring4/ch5/springJdbcAnnotations/test-data.sql")
                .addScripts("classpath:ProSpring4/ch5/springJdbcAnnotations/schema.sql", "classpath:ProSpring4/ch5/springJdbcAnnotations/test-data.sql")
                .build();
    }



    @Bean
    public ContactDao contactDao(DataSource dataSource) {
        return new JdbcContactDao(dataSource);
    }
}
